<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type">
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>所在地区</span>
              <el-cascader
                class="tel-value"
                v-model="params_list.address"
                :options="options"
                :props="props"
                @change="handleChange">
              </el-cascader>
            </div>
            <div class="item-inline">
              <span>采购方/结算方</span>
              <el-input class="tel-value" v-model="params_list.name" placeholder="请输入采购方/结算方名称"></el-input>
            </div> 
            <div class="item-inline">
              <span>受益人ID</span>
              <el-input class="tel-value" v-model="params_list.id" placeholder="请输入受益人ID"></el-input>
            </div>
            <div class="item-inline">
              <span>订单开始时间</span>
              <el-date-picker
                class="tel-value"
                v-model="params_list.start"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择订单开始时间"
                align="right">
              </el-date-picker>
            </div>
            <div class="item-inline">
              <span>订单结束时间</span>
              <el-date-picker
                class="tel-value"
                v-model="params_list.end"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择订单结束时间"
                align="right">
              </el-date-picker>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          预定服务单列表
          <div class="add-new">
            <el-button class="jx-btn" type="primary" :loading="boo.isExport" @click="exportRow">{{boo.isExport ? '请稍后……' : '导出'}}</el-button>
          </div>
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="institutionOrderNo" label="预定单号" width="150" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">{{scope.row.institutionOrderNo}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="balanceUnitName" label="采购方/结算方" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="serviceProductName" label="产品名称" align="center" show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="wrong" label="受益人ID" align="center" show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="institutionOrderAt" label="预定时间" align="center" show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column label="有效期" align="center" width="150" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <div>{{scope.row.institutionOrderValidBeginAt}}</div>
              <div>{{scope.row.institutionOrderValidEndAt}}</div>
            </template>
          </el-table-column>
          <el-table-column prop="institutionOrderAmount" label="数量" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="institutionOrderUseAmount" label="已使用数量" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="institutionOrderPrice" label="预购价格" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="institutionOrderSum" label="预购总价" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="validStatus" label="服务单状态" align="center">
          </el-table-column>
           <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button v-if="scope.row.validStatus == '有效'" @click="hiddenRow(scope.row)" type="text" size="small">终止</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
           <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
        https: {
          list: this.$api.order.supplier,
          common: this.$api.common
        },
        boo: {
          loading: false,
          isExport: false,
        },
        other: {
          allRow: 1,
        },
        list: '',
        params_list: {
          page: 1,
          size: 10,
          start: '',
          end: '',
          name: '',
          id: '',
          address: '',
        },
        props: {
          expandTrigger: 'click', 
          value: 'field',
          label: 'field',
        },
        options: [],
			}
		},
		mounted(){
      let _self = this
      _self.getList()
      _self.getAddress()
    },
		methods: {
      getAddress(){
        let _self = this
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.options = res.retObject
          }else{
            _self.$message.error(res.retMsg)
          }
        }
        _self.$axios.get(_self.https.common.address, {}, success) 
      },
      getList(){
        let _self = this
        let params = {
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
          orderBy: '',
          institutionOrderBeginAt: _self.params_list.start,
          institutionOrderEndAt: _self.params_list.end,
          institutionProvinceCity: _self.params_list.address,
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.list = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.list.list, params, success) 
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      search(){
        let _self = this
        _self.getList()
      },
      exportRow(){

      },
      hiddenRow(){

      },
      viewRow(item){
        console.log("========");
        console.log(item);
        
        let _self = this
        let params = {
          path: '/order/detail/supplier_detail?id=',
          query: item.institutionOrderNo
        }
        _self.$router.push(params.path + params.query)
      },
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 92px
  .jx-table
    /deep/ .el-table__body td
      .cell
        height: auto
        line-height: auto
</style>
